package com.simdo.g768.Util;

import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;

import com.simdo.g768.R;

import java.util.HashMap;

public class SoundUtil {
    private SoundPool soundPool;
    private HashMap<Integer, Integer> soundPoolMap;
    private Context context;

    public SoundUtil(Context context) {
        this.context = context;
        if (soundPool == null) {
            soundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
            soundPoolMap = new HashMap<>();
            loadSounds();
        }
    }

    public void loadSounds() {
        // 加载声音资源
        soundPoolMap.put(1, soundPool.load(context, R.raw.sound_tip, 1));
    }

    public void playSound(int sound) {
        // 播放声音
        soundPool.play(soundPoolMap.get(sound), 1.0f, 1.0f, 1, 0, 1.0f);
    }
}
